<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>apache 的动态和静态 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>apache 的动态和静态</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Apache/">Apache</a> <a class="article__tag-link" href="/tags/LAMP/">LAMP</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>关于apache的动态与静态编译的理解</strong>，引用某人的比喻如下：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;好比有两个人a和m，a代表apache,m代表module，要想让a使用m的东西，一个方法是把m的东西都放到a那里去，a使用的时候就是现成的了，就是所谓的静态编译</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;还有一个方法，就是告诉a，m的住址，当a要使用m的东西的时候,a去找m,然后使用，不过，这种方法要注意的一个问题就是：m必须要有实际的住址，否则a会找不到m而产生错误的，这种方法也就是apache 的动态(DSO)编译了。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>下面说说在apache1.3和apache2.0动态与静态编译编译的区别</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;首先是<strong>apache1.3.29</strong>+php4.3.4+mysql4.0.13的<strong>静态编译</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;apache第一次编译,并不要安装，因为php的编译需要apache至少已经编译过一次 </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">tar zvxf apache_1.3.27.tar.gz </div><div class="line"><span class="built_in">cd</span> apache_1.3.27 </div><div class="line">./configure --prefix=/usr/<span class="built_in">local</span>/apache</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编译php</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">tar zvxf php4.3.4.tar.gz </div><div class="line"><span class="built_in">cd</span> php4.3.4</div><div class="line">./configure --prefix=/usr/<span class="built_in">local</span>/php \</div><div class="line">--with-mysql=/usr/<span class="built_in">local</span>/mysql \</div><div class="line">--with-apache=../apache_1.3.27 </div><div class="line">make</div><div class="line">make install</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;第二次编译安装apache: </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">cd</span> ../apache_1.3.29</div><div class="line">./configure --prefi=/usr/<span class="built_in">local</span>/apache \</div><div class="line">--activate-module=src/modules/php4/libphp4.a </div><div class="line">make </div><div class="line">make install</div><div class="line">cp ../php4.3.4/php.ini.dist /usr/<span class="built_in">local</span>/php/lib/php.ini</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改/usr/local/apache/conf/httpd.conf</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;查找<ifmodule mod_mime.c=""></ifmodule></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在此范围添加</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">AddType application/x-httpd-php .php </div><div class="line">AddType application/x-httpd-php-source .phps</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;注意：apache和php的源码包在同一个目录，–with-apache=../apache_1.3.27是指向源码解压的目录</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;ok!静态编译完成。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;再看<strong>DSO动态编译</strong>方法：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;首先编译安装apache</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">tar zvxf apache_1.3.29</div><div class="line"><span class="built_in">cd</span> apache_1.3.29</div><div class="line">./configure --prefix=/usr/<span class="built_in">local</span>/apache \</div><div class="line">--<span class="built_in">enable</span>-module=so \</div><div class="line">--<span class="built_in">enable</span>-module=rewrite \</div><div class="line">--<span class="built_in">enable</span>-shared=max</div><div class="line">make </div><div class="line">make install</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;so模块用来提供DSO支持的apachehe核心模块，rewrite是地址重写的模块，如果不需要可以不编译enable－shared＝max是指除了so以外的所有标准模块都编译成DSO模块。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后编译php</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">tar zvxf php4.3.4.tar.gz </div><div class="line"><span class="built_in">cd</span> php4.3.2 </div><div class="line">./configure --prefix=/usr/<span class="built_in">local</span>/php \</div><div class="line">--with-mysql=/usr/<span class="built_in">local</span>/mysql \</div><div class="line">--with-apxs=/usr/<span class="built_in">local</span>/apache/bin/apxs </div><div class="line">make</div><div class="line">make install</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后修改httpd.conf，方法同静态编译的方法</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;OK，DSO动态编译就完成了！</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;接下来我们讲<strong>apache2.0.46</strong>+php4.3.2的<strong>动态编译</strong>方法</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;一样先编译安装apache</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">tar zvxf httpd-2.0.46.tar.gz</div><div class="line"><span class="built_in">cd</span> httpd-2.0.46</div><div class="line">./configure --prefix=/usr/<span class="built_in">local</span>/apache2 \</div><div class="line">--<span class="built_in">enable</span>-so \</div><div class="line">--<span class="built_in">enable</span>-mods-shared=most</div><div class="line">make</div><div class="line">make install</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>大家注意了–enable-so相当与1.3.27的–enable-module=so，而–enable-mods-shared=most又等同与以前的–enable-shared=max</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后还是编译PHP</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">tar zvxf php4.3.2.tar.gz</div><div class="line">./configure --prefix=/usr/<span class="built_in">local</span>/php \</div><div class="line">--with-mysql=/usr/<span class="built_in">local</span>/mysql \</div><div class="line">--with-apxs2=/usr/<span class="built_in">local</span>/apache2/bin/apxs </div><div class="line">make </div><div class="line">make install</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>注意这里是apxs2！！</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改httpd.conf与1.3.27也有所不同，大家寻找Add Type application/x-tar .tgz 在下面添加</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">AddType application/x-httpd-php .php </div><div class="line">AddType application/x-httpd-php-source .phps</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;另外要显示中文的话，请修改:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">AddDefaultCharset gb2312</div></pre></td></tr></table></figure>

	

	
		<span class="different-posts"><a href="/2017/10/12/Apache/12. apache 的动态和静态/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
